package com.qpcy.controller;

import com.mybatisflex.core.paginate.Page;
import com.qpcy.utils.ResponseResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.qpcy.entity.Video;
import com.qpcy.service.VideoService;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
import java.util.List;

/**
 *  控制层。
 *
 * @author DELL
 * @since 2024-10-20
 */
@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 获取分页
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResponseResult list(int pageNum, int pageSize) {
        Page<Video> videoPage = new Page<>(pageNum, pageSize);
        Page<Video> page = videoService.page(videoPage);
        return ResponseResult.success(page);
    }

    /**
     * 保存视频
     *
     * @param video
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody Video video) {
        return ResponseResult.success(videoService.save(video));
    }

    /**
     * 修改视频
     *
     * @param video
     * @return
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody Video video) {
        return ResponseResult.success(videoService.updateById(video));
    }

    /**
     * 删除视频
     *
     * @param videoId
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult delete(int videoId) {
        return ResponseResult.success(videoService.removeById(videoId));
    }

}
